package com.kaibes.imserver.model.database;

import java.sql.ResultSet;
import java.sql.SQLException;

public class UsercenterHelper extends DatabaseHelper {

	private static UsercenterHelper instance = null;
	
	private UsercenterHelper(String database) {
		super(database);
	}
	
	public String getUserPassword(String username) {
		ResultSet result = select("userinformation", "password", "username=?",
				new String[] { username });

		if (result != null) {
			try {
				result.next();
				return result.getString("password");
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return null;
	}

	public ResultSet getUserinformationResultSet(String username) {
		return select("userinformation", "*", "username=?",
				new String[] { username });
	}

	public int insertUserinformation(String username, String password,
			String question, String answer) {
		try {
			return insert("userinformation", "username,password,question,answer", new String[] { username,
					password, question, answer });
		} catch (SQLException e) {
			System.err.println("重复插入用户信息");
//			e.printStackTrace();
		}
		return 0;
	}
	
	public static void Initialize() {
		instance = new UsercenterHelper("usercenter");
	}
	
	public static UsercenterHelper getInstance(){
		return instance;
	}
	
	@Override
	protected UsercenterHelper clone() throws CloneNotSupportedException {
		return getInstance();
	}
}
